package cn.zyzpp.service.resume.impl;

import cn.zyzpp.dao.AcademicDao;
import cn.zyzpp.entity.resume.Academic;
import cn.zyzpp.service.resume.AcademicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Create by yster@foxmail.com 2018/5/21/021 22:19
 */
@Service
@CacheConfig(cacheNames = {"AcademicService"})
public class AcademicServiceImpl implements AcademicService {
    @Autowired
    private AcademicDao academicDao;

    @Override
    @CacheEvict(allEntries = true)
    public void save(Academic academic, int uid) {
        academic.setUid(uid);
        academicDao.save(academic);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void delect(int id) {
        academicDao.deleteAllById(id);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataByUid(Academic academic) {
        Academic academic1 = academicDao.findByUid(academic.getUid());
        academic1.updata(academic);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public List<Academic> queryAll(int uid) {
        return academicDao.findAllByUid(uid);
    }
}
